package com.cabal.common.config;

import com.cabal.common.util.SnowflakeIdUtil;
import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * AliyunOSS配置类
 *
 * @author shenkang
 * @data 2022年4月28日
 */
@Configuration
@Component
@Data
public class AliyunOSSConfig implements InitializingBean {
    private Logger logger = LoggerFactory.getLogger(AliyunOSSConfig.class);

    //@Value("${aliyun.oss.bucketname}")
    private String bucketname;

    //@Value("${aliyun.oss.endpoint}")
    private String endpoint;

    //@Value("${aliyun.oss.keyid}")
    private String keyid;

    //@Value("${aliyun.oss.keysecret}")
    private String keysecret;

    //@Value("${aliyun.oss.filehost}")
    private String filehost;

    //@Value("${aliyun.oss.upload.file.path}")
    private String uploadFilePath = "D:\\CC\\";

    // 报表服务路径一致
    //@Value("${aliyun.oss.rootPath}")
    private String rootPath = "D:\\crfp_dev\\";


    public static String ALIYUN_OSS_BUCKETNAME;
    public static String ALIYUN_OSS_ENDPOINT;
    public static String ALIYUN_OSS_KEYID;
    public static String ALIYUN_OSS_KEYSECRET;
    public static String ALIYUN_OSS_FILEHOST;
    public static String ALIYUN_OSS_UPLOAD_FILE_PATH;
    public static String ALIYUN_OSS_ROOT_PATH;

    private final static String WAITING_UPLOAD_PATH = "WaitingUpload/";
    private final static String UPLOADED_PATH = "Uploaded/";
    private final static String RETURN_RECEIPT = "ReturnReceipt/";
    private final static String ZIP_PATH = "Zip/";

    @Override
    public void afterPropertiesSet() throws Exception {

        ALIYUN_OSS_BUCKETNAME = bucketname;
        ALIYUN_OSS_ENDPOINT = endpoint;
        ALIYUN_OSS_KEYID = keyid;
        ALIYUN_OSS_KEYSECRET = keysecret;
        ALIYUN_OSS_FILEHOST = filehost;
        ALIYUN_OSS_UPLOAD_FILE_PATH = uploadFilePath;
        ALIYUN_OSS_ROOT_PATH = rootPath;

    }

     /**
      * 获取已加签待上传OSS地址
      * @author zhaojq<jovenkingzhao @ jieztech.com>
      * @date 2022-05-05 11:49
      */
    public String getWaitingUploadOSSPath(String customTenCode){
        return ALIYUN_OSS_ROOT_PATH.concat(WAITING_UPLOAD_PATH).concat(customTenCode).concat("/");
    }

     /**
      * 获取已经上传的报文OSS地址
      * @author zhaojq<jovenkingzhao @ jieztech.com>
      * @date 2022-05-05 11:49
      */
    public String getUploadedOSSPath(String customTenCode){
        return ALIYUN_OSS_ROOT_PATH.concat(UPLOADED_PATH).concat(customTenCode).concat("/");
    }

    /**
     * 获取企业报文回执OSS地址
     * @author zhaojq<jovenkingzhao @ jieztech.com>
     * @date 2022-05-06 14:34
     */
    public String getReturnReceiptOSSPath(String customTenCode){
        return ALIYUN_OSS_ROOT_PATH.concat(RETURN_RECEIPT).concat(customTenCode).concat("/");
    }


    /**
     * 获取文件上传压缩包存放文件夹
     * @author lzy
     * @date 2022-05-16 15:34
     */
    public String getZipFileOSSPath(){
        Long id = SnowflakeIdUtil.getInstance().nextId();
        return ALIYUN_OSS_ROOT_PATH.concat(ZIP_PATH).concat(id.toString()).concat("/");
    }

}